package com.xhl.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xhl.entity.User;
import com.xhl.mapper.UserMapper;
import com.xhl.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author xhlMr
 * @since 2020-07-29
 */
@Service
@Slf4j
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    //查询
    @Override
    @Cacheable(value = "test:user",key = "#id")//test:user:1
    public User userbyid(Integer id) {
        log.info("user =>"+id);
        return userMapper.userbyid(id);
    }

    @Override
    @CacheEvict(value="test:user",key="#p0.id")
    public Integer updbyid(User user) {
        return userMapper.updbyid(user);
    }

    //删除 删除数据库删除缓存
    @Override
    @CacheEvict(value="test:user",key="#id")
    public Integer delbyid(Integer id) {
        return userMapper.delbyid(id);
    }
}
